import {Component, OnInit} from '@angular/core';
import {Router} from "@angular/router";
import {Jsonp} from "@angular/http";
import 'rxjs';
import {TranslateService} from "ng2-translate";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit{

  constructor(public routerInfo: Router,public jsonp: Jsonp,public translate: TranslateService){
 //   let wikiUrl = 'http://localhost:3001/api/products?callback=JSONP_CALLBACK';
    // 定义参数
/*    var params = new URLSearchParams();
    params.set('callback', 'JSONP_CALLBACK');*/
/*
      this.jsonp.get(wikiUrl).map(res=> res.json()).subscribe(e=>{
        console.log(e);
      })*/
  }

  ngOnInit() {
    this.translate.addLangs(["zh", "en"]);
    this.translate.setDefaultLang('zh');

    const browserLang = this.translate.getBrowserLang();
    console.log("检测到的浏览器语言>" + browserLang);
    this.translate.use(browserLang.match(/zh|en/) ? browserLang : 'zh');
  }
}
